#include <iostream>
using namespace std;

int bsearch(int array[], int l, int h, int target)
{
	int low = l;
	int high = h;
	int mid;
	while(low <= high)
	{
		mid = (low+high)/2;
		if(array[mid] == target)
			return target;
		else if(array[mid] > target)
			high = mid - 1;
		else
			low = mid + 1;	
	}
	return -1;
}


int main()
{
	int array[10] = {1,2,3,4,5,6,8,9,10,11};
	cout << "find 3 ? : " << bsearch(array,0,9,3) << endl;
	cout << "find 7 ? : " << bsearch(array,0,9,7) << endl;  
	cout << "find 0 ? : " << bsearch(array,0,9,0) << endl;  
	cout << "find 12 ? : " << bsearch(array,0,9,12) << endl;  
	return 0;
}
